
import Observer from './observer'
import Compiler from './compiler'
class Jue {
    constructor (options) {
        //保持数据
        this.$options = options || {}
        this.$data = options.data || {}
        this.$el = typeof options.el === 'string' ? document.querySelector(options.el) : options.el

        //改成setter getter
        this._proxyData(this.$data)
        //创建 observer
        new Observer(this.$data)
        new Compiler(this)
    }
    _proxyData (data) {
        //遍历data属性
        console.log(Object.keys(data))
        Object.keys(data).forEach(key =>{
            Object.defineProperty(this,key,{
                enumerable: true,
                configurable: true,
                get(){
                    return data[key]
                },
                set(newValue){
                    if(newValue === data[key]){
                        return
                    }
                    data[key] = newValue

                }
            })
        })
        //注入Vue实例
    }
}
export default Jue